/**
 * Project Name:EMSInterfaceTest
 * File Name:PayController.java
 * Package Name:functions.ems_payment
 * Date:2018年7月27日下午4:05:11
 * Copyright (c) 2018, crpcg@crpcg.com All Rights Reserved.
 *
 */

package functions.ems_payment;
/**
 *     
 * @author  chenhailian6 	 
 */


import java.util.HashMap;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import coms.Constants;
import frame.HttpHelper;


public class PayLineController {
	private static Logger logger = LoggerFactory.getLogger(PayLineController.class);
	String result;
	String ids;
	String payHeadId;
	boolean isPassed;
	JSONArray queryPayLineInfoJsonArray;
	
	public JSONArray getQueryPayLineInfoJsonArray() {
		return queryPayLineInfoJsonArray;
	}

	public void setQueryPayLineInfoJsonArray(JSONArray queryPayLineInfoJsonArray) {
		this.queryPayLineInfoJsonArray = queryPayLineInfoJsonArray;
	}

	public void queryPayLineInfo(HashMap<Object,Object> inputParams) {
		logger.info("queryPayLineInfo  --- start ---------------------");
		String currentPage = "1";
		String pageSize = "10";
		String batchId = "";
		String claimId = "";
		String claimNo = "";
		String invoiceNo = "";
		String payPlanId = "";
		String payRequestLineId = "";
		String fieldName  = "";
		String orderBy = "";
		if(inputParams != null) {
			currentPage = (String) inputParams.get("currentPage");
			if(currentPage == null) {
				currentPage = "1";
			}
			pageSize = (String) inputParams.get("pageSize");
			if(pageSize == null) {
				pageSize = "10";
			}
			batchId = (String) inputParams.get("batchId");
			if(batchId == null) {
				batchId = "";
			}
			claimId = (String) inputParams.get("claimId");
			if(claimId == null) {
				claimId = "";
			}
			claimNo = (String) inputParams.get("claimNo");
			if(claimNo == null) {
				claimNo = "";
			}
			invoiceNo = (String) inputParams.get("invoiceNo");
			if(invoiceNo == null) {
				invoiceNo = "";
			}
			payPlanId = (String) inputParams.get("payPlanId");
			if(payPlanId == null) {
				payPlanId = "";
			}
			payRequestLineId = (String) inputParams.get("payRequestLineId");
			if(payRequestLineId == null) {
				payRequestLineId = "";
			}
			fieldName = (String) inputParams.get("fieldName");
			if(fieldName == null) {
				fieldName = "";
			}
			orderBy = (String) inputParams.get("orderBy");
			if(orderBy == null) {
				orderBy = "";
			}
		}
		String params = "{\"page\":{\"currentPage\":"+currentPage+",\"pageSize\":"+pageSize+",\"recordCount\":0},"
				+ "\"params\":{\"batchId\":\""+batchId+"\",\"claimId\":\""+claimId+"\",\"claimNo\":\""+claimNo+"\","
				+ "\"invoiceNo\":\""+invoiceNo+"\",\"payPlanId\":\""+payPlanId+"\",\"payRequestLineId\":\""+payRequestLineId+"\"},"
				+ "\"sortDTO\":{\"fieldName\":\""+fieldName+"\",\"orderBy\":\""+orderBy+"\"}}";
		
		String url = Constants.QUERY_PAY_LINE_INFO_URL;
		try {
			result = HttpHelper.post(params, url);
			isPassed = HttpHelper.isOk;
			logger.info("queryPayLineInfo--------"+ result);
			if(isPassed) {
				try {
					JSONObject datas = new JSONObject(result);
					int total = datas.getInt("total");
					if(total >0) {
						try {
							queryPayLineInfoJsonArray = datas.getJSONArray("list");
							for(int i = 0;i<queryPayLineInfoJsonArray.length();i++) {
								JSONObject object = queryPayLineInfoJsonArray.getJSONObject(i);
								logger.info(object.toString());
							}
						
						}catch(JSONException e) {
							e.printStackTrace();
						}
						
					}
				}catch(Exception e) {
					e.printStackTrace();
					isPassed = false;
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info(" 返回结果  ------" + isPassed);
		logger.info("queryPayLineInfo  --- end ---------------------");
	}
	
	
	



	
}

